package top.jolyoulu.core.rdd.lineage

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @Author: JolyouLu
 * @Date: 2024/5/12 17:06
 * @Description
 */
object Spark01_RDD_Dep {
  def main(args: Array[String]): Unit = {
    //准备环境 [*]:表示使用当前系统最大核
    val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    val sc: SparkContext = new SparkContext(sparkConf)

    val path: String = this.getClass.getClassLoader.getResource("datas/1.txt").toURI.getPath
    val fileRDD: RDD[String] = sc.textFile(path)
    println(fileRDD.dependencies)
    println("---------------------------------")

    val wordRDD: RDD[String] = fileRDD.flatMap(_.split(" "))
    println(wordRDD.dependencies)
    println("---------------------------------")

    val mapRDD: RDD[(String, Int)] = wordRDD.map((_, 1))
    println(mapRDD.dependencies)
    println("---------------------------------")

    val resultRDD: RDD[(String, Int)] = mapRDD.reduceByKey(_ + _)
    println(resultRDD.dependencies)
    println("---------------------------------")

    resultRDD.collect()
    sc.stop()
  }
}

